'use strict';

const {Controller} = require('egg');
const ResponseUtil = require('../utils/ResponseUtil');

class UserController extends Controller {

    async getUserList() {
        let query = this.ctx.query;
        const res = await this.ctx.service.user.getUserList(query);
        return this.ctx.body = ResponseUtil.success(res.list, res.total);
    }

    async getUserDetail(){
        const res = await this.ctx.service.user.getUserDetail();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async userAuditSwitch(){
        const res = await this.ctx.service.user.userAuditSwitch();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async updateUserStatus(){
        const res = await this.ctx.service.user.updateUserStatus();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async getUserAuthAuditList(){
        let query = this.ctx.query;
        const res = await this.ctx.service.user.getUserAuthAuditList(query);
        return this.ctx.body = ResponseUtil.success(res.list, res.total);
    }

    async getUserAuthAuditDetail(){
        const res = await this.ctx.service.user.getUserAuthAuditDetail();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async userAuthAudit(){
        const res = await this.ctx.service.user.userAuthAudit();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async userAuthAction(){
        const res = await this.ctx.service.user.userAuthAction();
        return this.ctx.body = ResponseUtil.success(res);
    }

    async getUserBalance(){
        let {userId} = this.ctx.query;
        if(!userId){
            return this.ctx.body = ResponseUtil.retArgErr();
        }
        const res = await this.ctx.service.balance.getUserBalance(userId);
        return this.ctx.body = ResponseUtil.success(res);
    }

    async getUserBalanceDetail(){
        const res = await this.ctx.service.balance.getUserBalanceDetail();
        return this.ctx.body = ResponseUtil.success(res.list,res.total);
    }

    async saveUserMargin(){
        const res = await this.ctx.service.user.saveUserMargin();
        return this.ctx.body = ResponseUtil.success(res);
    }

}

module.exports = UserController;
